package com.ruoyi.bizsys.service.impl;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.bizsys.vo.CustBindCardLogVo;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.stereotype.Service;
import com.ruoyi.bizsys.mapper.CustBindCardLogMapper;
import com.ruoyi.bizsys.domain.CustBindCardLog;
import com.ruoyi.bizsys.service.ICustBindCardLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;


/**
 * 客户绑卡记录Service业务层处理
 *
 * @author african-loan
 * @date 2021-12-30
 */
@Service
public class CustBindCardLogServiceImpl extends ServiceImpl<CustBindCardLogMapper,CustBindCardLog> implements ICustBindCardLogService {

    private final static List<String> TRANS_STATUS_LIST = Arrays.asList("2", "3", "9");

    /**
     * 查询客户绑卡记录
     *
     * @param id 客户绑卡记录ID
     * @return 客户绑卡记录
     */
    @Override
    public CustBindCardLog selectCustBindCardLogById(Long id) {
        return this.getById(id);
    }

    /**
     * 查询客户绑卡记录列表
     *
     * @param custBindCardLog 客户绑卡记录
     * @return 客户绑卡记录
     */
    @Override
    public List<CustBindCardLog> selectCustBindCardLogList(CustBindCardLog custBindCardLog) {
        return this.list(new QueryWrapper<>(custBindCardLog).last("order by id desc"));
    }

    /**
     * 新增客户绑卡记录
     *
     * @param custBindCardLog 客户绑卡记录
     * @return 结果
     */
            @Override
    public int insertCustBindCardLog(CustBindCardLog custBindCardLog) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        custBindCardLog.setCreateTime(DateUtils.getNowDate());
                                                                                        return baseMapper.insert(custBindCardLog);
    }

    /**
     * 修改客户绑卡记录
     *
     * @param custBindCardLog 客户绑卡记录
     * @return 结果
     */
            @Override
    public int updateCustBindCardLog(CustBindCardLog custBindCardLog) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                custBindCardLog.setUpdateTime(DateUtils.getNowDate());
                                                return baseMapper.updateById(custBindCardLog);
    }

    /**
     * 批量删除客户绑卡记录
     *
     * @param ids 需要删除的客户绑卡记录ID
     * @return 结果
     */
            @Override
    public int deleteCustBindCardLogByIds(Long[] ids) {
        return baseMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除客户绑卡记录信息
     *
     * @param id 客户绑卡记录ID
     * @return 结果
     */
    @Override
    public int deleteCustBindCardLogById(Long id) {
        return baseMapper.deleteById(id);
    }

    @Override
    public List<CustBindCardLogVo> selectCustBindCardLogVo(CustBindCardLogVo custBindCardLogVo) {
        return baseMapper.selectCustBindCardLogVo(custBindCardLogVo);
    }

    @Override
    public int getTransCount(String custNo) {
        return count(new QueryWrapper<CustBindCardLog>().eq("cust_no", custNo).in("trans_status", TRANS_STATUS_LIST));
    }

    @Override
    public CustBindCardLog getDetailBySerialNo(String serialNo) {
        return baseMapper.getDetailBySerialNo(serialNo);
    }

}
